﻿using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace PLCS.App.EquipmentManager.Converts;

internal class VisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (bool.TryParse(value?.ToString(), out bool result))
        {
            return result ? Visibility.Visible : Visibility.Collapsed;
        }

        return Visibility.Collapsed;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value != null && bool.TryParse(value.ToString(), out bool result))
        {
            if (!result)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        return true;
    }
}